<!--
//******************************************************************
//* Copyright (c) 2008 Ford Motor Company. All Rights Reserved.
//*
//*
//* $$Workfile:   costStructureNew.jsp  $$
//* $$Revision:   1.0  $$
//* $$Author:   JLOPE262  $$
//* $$Date:   Nov 14 2008 08:57:48  $$
//*
//* Description: Description of file goes here
//******************************************************************
-->
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://displaytag.sf.net/el" prefix="display-el" %>
<%@ taglib uri="ford-arg/tags" prefix="ft" %>

<script language="JavaScript" src="./scripts/popups.js"></script>
<script language="JavaScript" src="./scripts/CalendarPopup.js"></script>
<script language="JavaScript" src="./scripts/ajaxSearch.js"></script>

<script language="javascript">		
	var cal = new CalendarPopup(); 
	cal.showNavigationDropdowns();
	cal.setMonthNames('<bean:message key="label.month.january"/>',
						'<bean:message key="label.month.february"/>',
						'<bean:message key="label.month.march"/>',
						'<bean:message key="label.month.april"/>',
						'<bean:message key="label.month.may"/>',
						'<bean:message key="label.month.june"/>',
						'<bean:message key="label.month.july"/>',
						'<bean:message key="label.month.august"/>',
						'<bean:message key="label.month.september"/>',
						'<bean:message key="label.month.october"/>',
						'<bean:message key="label.month.november"/>',
						'<bean:message key="label.month.december"/>');
	cal.setDayHeaders('<bean:message key="label.day.sunday.capital"/>',
						'<bean:message key="label.day.monday.capital"/>',
						'<bean:message key="label.day.tuesday.capital"/>',
						'<bean:message key="label.day.wednesday.capital"/>',
						'<bean:message key="label.day.thursday.capital"/>',
						'<bean:message key="label.day.friday.capital"/>',
						'<bean:message key="label.day.saturday.capital"/>');
	cal.setTodayText('<bean:message key="label.today"/>');
	
	function lookupSupplier() {
		searchNameSupplier("lookupedSupplier", "supplierCode", "supplierClass");	
	}

	function lookupPart() {
		searchNamePart("lookupedPart", "partClass", "partPrefix", "partBase", "partSuffix");	
	}

	function save() {
		document.CostStructureNewForm.action = "CostStructureNewActionSave.do";
		document.CostStructureNewForm.section.value = "save";
		document.CostStructureNewForm.submit();	
	}
	
	function update() {
		document.CostStructureNewForm.action = "CostStructureNewActionUpdate.do";
		document.CostStructureNewForm.section.value = "update";
		document.CostStructureNewForm.submit();		
	}

	function propose() {
		document.CostStructureNewForm.action = "CostStructureNewActionPropose.do";
		document.CostStructureNewForm.section.value = "propose";
		document.CostStructureNewForm.submit();		
	}

	function approve() {
		document.CostStructureNewForm.action = "CostStructureNewActionApprove.do";
		document.CostStructureNewForm.section.value = "approve";
		document.CostStructureNewForm.submit();		
	}

	function back() {
		document.CostStructureNewForm.action = "CostStructureFindActionFind.do";
		document.CostStructureNewForm.submit();			
	}
	
	function details() {
		document.CostStructureNewForm.action = "CostStructureFindActionDetails.do";
		document.CostStructureNewForm.section.value = "details";
		document.CostStructureNewForm.submit();	
	}

	function enableDiv(id, status, clean) {
		var hijos = document.getElementById(id).childNodes;
		for (var i = 0; i < hijos.length; i++) {
			if (hijos[i].tagName=="SELECT" || hijos[i].tagName=="INPUT") {
				hijos[i].disabled = !status;
				if (clean) {
					if (hijos[i].tagName=="SELECT") {
						hijos[i].selectedIndex = 0;
					} else if (hijos[i].tagName=="INPUT" && hijos[i].type=="text") {
						hijos[i].value="";
					}
				}
			}
		};		
	}
	
	function onChangeAppliesTo(appliesTo) {
		if (appliesTo.selectedIndex == 0) {
			enableDiv("supplier", false, true);
			enableDiv("commodity", false, true);	
			enableDiv("part", false, true);				
		} else if (appliesTo.selectedIndex == 1) {
			enableDiv("supplier", true, true);
			enableDiv("commodity", false, true);			
			enableDiv("part", false, true);						
		} else if (appliesTo.selectedIndex == 2) {
			enableDiv("supplier", true, true);			
			enableDiv("commodity", true, true);			
			enableDiv("part", false, true);									
		} else if (appliesTo.selectedIndex == 3) {
			enableDiv("supplier", true, true);			
			enableDiv("commodity", false, true);			
			enableDiv("part", true, true);									
		}
	}

</script>

<table>
	<tr>
		<td><h2><bean:message key="costStructure.new.label.title"/></h2></td>
	</tr>
</table>
<br/>
<html:form action="/CostStructureNewActionInit">
<html:hidden property="section" />
	<logic:equal name="CostStructureNewForm" property="blockAppliesTo" value="true">
		<bean:define id="blockAppliesTo">true</bean:define>
	</logic:equal>
	<logic:equal name="CostStructureNewForm" property="blockAppliesTo" value="false">
		<bean:define id="blockAppliesTo">false</bean:define>
	</logic:equal>
	<table>
		<tr>
			<td  class="text_blue_bold align_left" colspan="100%">
				<bean:message key="costStructure.new.label.id" />: <bean:message key="costStructure.new.label.auto" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<bean:message key="costStructure.new.label.version" />: <bean:write name="CostStructureNewForm" property="version" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<b><bean:message key="costStructure.new.label.status" />: <bean:message key="label.draft" /></b>
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="costStructure.new.label.tier" />
			</td>
			<td class="text_blue_bold align_left">
				1
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="costStructure.new.label.description" />
			</td>
			<td class="align_left">
				<html:text property="description" maxlength="50" size="50" />
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="costStructure.new.label.appliesTo" />
			</td>
			<td class="align_left">
				<html:select property="costStructureTypeSel" styleId="appliesTo" onchange="onChangeAppliesTo(this);" disabled="${blockAppliesTo}">
					<html:option value="-1"><bean:message key="label.selectOption" /></html:option>				
					<html:options collection="typesCostStructureCol" property="value" labelProperty="label" />
				</html:select>
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="costStructure.new.label.supplier" />
			</td>
			<td class="text_blue_bold align_left">
			<div id="supplier">
				<html:select property="supplierTypeSel" disabled="${blockAppliesTo}" styleId="supplierClass">
					<html:option value="-1"><bean:message key="label.selectOption" /></html:option>				
					<html:options collection="supplierTypeCol" property="value" labelProperty="label" />
				</html:select>
				&minus;
				<html:text property="supplierCode" maxlength="6" size="6" disabled="${blockAppliesTo}" styleId="supplierCode"/>
				<html:button property="lookupSupp" onclick="lookupSupplier();" styleClass="button" disabled="${blockAppliesTo}">...</html:button>
				<html:button property="findSupplier" onclick="findSupplierPopup('supplierClass', 'supplierCode');" styleClass="button" style="width:25px;" disabled="${blockAppliesTo}">?</html:button>
				<div style="display:inline;" id="lookupedSupplier" />
			</div>
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="commodity.label" />
			</td>
			<td class="align_left">			
			<div id="commodity">
				<html:select property="commoditySel" disabled="${blockAppliesTo}">
					<html:option value="-1"><bean:message key="label.selectOption" /></html:option>
					<html:options collection="commoditiesCol" property="eesp02CommodityNumberK" labelProperty="eesp02CommodityNameN" />
				</html:select>			
			</div>				
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="part.label" />
			</td>
			<td class="align_left">
			<div id="part">
				<html:select property="partClassSel" disabled="${blockAppliesTo}" styleId="partClass">
					<html:option value="-1"><bean:message key="label.selectOption" /></html:option>				
					<html:options collection="partClassesCol" property="value" labelProperty="label" />
				</html:select>
				&minus;
				<html:text property="partPrefix" maxlength="10" size="10" disabled="${blockAppliesTo}" styleId="partPrefix" />
				&nbsp;
				<html:text property="partBase" maxlength="10" size="10" disabled="${blockAppliesTo}" styleId="partBase" />
				&nbsp;
				<html:text property="partSufix" maxlength="10" size="10" disabled="${blockAppliesTo}" styleId="partSuffix" />
				<html:button property="lookPart" onclick="lookupPart();" styleClass="button" disabled="${blockAppliesTo}">...</html:button>
				<html:button property="findPart" onclick="findPartPopup('supplierClass', 'supplierCode', 'partClass', 'partPrefix', 'partBase', 'partSuffix');" styleClass="button" style="width:25px;" disabled="${blockAppliesTo}">?</html:button>
				<div style="display:inline;" id="lookupedPart" />
			</div>
			</td>			
		</tr>
		<tr>
			<td class="text_blue_bold align_left">
				<bean:message key="costStructure.new.label.dateIn" />
			</td>
			<td class="text_blue_bold align_left">
				<html:text property="dateIn" maxlength="10" size="10"/><A name="dateInAnchor"> </A><html:button property="calendarIn" onclick="cal.select(document.CostStructureNewForm.dateIn,'dateInAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>				
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<bean:message key="costStructure.new.label.dateOut" />&nbsp;&nbsp;
				<html:text property="dateOut" maxlength="10" size="10"/><A name="dateOutAnchor"> </A><html:button property="calendarOut" onclick="cal.select(document.CostStructureNewForm.dateOut,'dateOutAnchor','dd/MM/yyyy'); return false;" styleClass="button_small">...</html:button>				
			</td>
		</tr>
		<tr>
			<td class="text_blue_bold align_left" colspan="100%">
				<bean:message key="costStructure.new.label.obs" />
			</td>
		</tr>
		<tr>
			<td class="align_left" colspan="100%">
				<html:text property="observations" maxlength="500" style="width:800px;"/>
			</td>
		</tr>
	<logic:equal name="CostStructureNewForm" property="comeFrom" value="header">
		<tr>
			<td style="height:15px;" />
		</tr>
		<tr>
			<td class="align_right" colspan="100%">
				<html:button property="updateCS" onclick="update();" styleClass="button"><bean:message key="label.update" /></html:button>
			</td>
		</tr>
	</logic:equal>
	</table>
	<br />
	<br />
	<br />
	<br />
	<table style="width: 800px;">
		<tr>
			<td class="align_left">			
				<table align="left" class="table1" style="width: 590px;">
					<tr>
						<td class="align_left">									
							<logic:empty property="createdBy" name="CostStructureNewForm">
								<html:button property="saveCS" onclick="save();" styleClass="button_small"><bean:message key="label.save" /></html:button>
							</logic:empty>
							<logic:notEmpty property="createdBy" name="CostStructureNewForm">
								<bean:define id="createdBy" name="CostStructureNewForm" property="createdBy" />
								<bean:define id="createdDate" name="CostStructureNewForm" property="createdDate" />
								<bean:message key="text.createdBy" arg0="${createdBy}" arg1="${createdDate}" />
							</logic:notEmpty>
						</td>
					</tr>
					<tr>
						<td class="align_left">
							<logic:notEmpty property="createdBy" name="CostStructureNewForm">
								<logic:empty property="proposedBy" name="CostStructureNewForm">
									<html:button property="proposeCS" onclick="propose();" styleClass="button_small"><bean:message key="label.propose" /></html:button>
								</logic:empty>
							</logic:notEmpty>
							<logic:notEmpty property="proposedBy" name="CostStructureNewForm">
								<bean:define id="proposedBy" name="CostStructureNewForm" property="proposedBy" />
								<bean:define id="proposedDate" name="CostStructureNewForm" property="proposedDate" />
								<bean:message key="text.proposedBy" arg0="${proposedBy}" arg1="${proposedDate}" />
							</logic:notEmpty>
						</td>								
					</tr>
					<tr>
						<td class="align_left">
							<logic:notEmpty property="proposedBy" name="CostStructureNewForm">
								<logic:empty property="approvedBy" name="CostStructureNewForm">
									<html:button property="approveCS" onclick="approve();" styleClass="button_small"><bean:message key="label.approve" /></html:button>											
								</logic:empty>											
							</logic:notEmpty>
							<logic:notEmpty property="approvedBy" name="CostStructureNewForm">
								<bean:define id="approvedBy" name="CostStructureNewForm" property="approvedBy" />
								<bean:define id="approvedDate" name="CostStructureNewForm" property="approvedDate" />
								<bean:message key="text.approvedBy" arg0="${approvedBy}" arg1="${approvedDate}" />
							</logic:notEmpty>
						</td>
					</tr>
					<tr>
						<td class="align_left">
							<logic:notEmpty property="lastModifiedBy" name="CostStructureNewForm">
								<bean:define id="lastModifiedBy" name="CostStructureNewForm" property="lastModifiedBy" />
								<bean:define id="lastModifiedDate" name="CostStructureNewForm" property="lastModifiedDate" />										
								<bean:message key="text.lastModifiedBy" arg0="${lastModifiedBy}" arg1="${lastModifiedDate}" />											
							</logic:notEmpty>
						</td>
					</tr>
				</table>
			</td>
			<td class="align_right">
				<logic:notEqual name="CostStructureNewForm" property="comeFrom" value="menu">
					<html:button property="backCS" onclick="back();" styleClass="button"><bean:message key="label.back" /></html:button>
				</logic:notEqual>
				<html:button property="detailsCS" onclick="details();" styleClass="button"><bean:message key="label.details" /></html:button>
			</td>
		</tr>		
	</table>
</html:form>

<script language="javascript">
	var appliesTo = document.getElementById("appliesTo");
	if (appliesTo.selectedIndex == 0) {
		enableDiv("supplier", false, true);
		enableDiv("commodity", false, true);	
		enableDiv("part", false, true);	
	} 
	
<logic:equal name="CostStructureNewForm" property="blockAppliesTo" value="false">
	if (appliesTo.selectedIndex == 1) {
		enableDiv("supplier", true, false);
		enableDiv("commodity", false, false);	
		enableDiv("part", false, false);		
	} else if (appliesTo.selectedIndex == 2) {
		enableDiv("supplier", true, false);
		enableDiv("commodity", true, false);	
		enableDiv("part", false, false);			
	} else if (appliesTo.selectedIndex == 3) {
		enableDiv("supplier", true, false);
		enableDiv("commodity", false, false);	
		enableDiv("part", true, false);			
	}	
</logic:equal>

</script>